define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'lihua_wallet_order/index' + location.search,
                    add_url: 'lihua_wallet_order/add',
                    edit_url: 'lihua_wallet_order/edit',
                    del_url: 'lihua_wallet_order/del',
                    multi_url: 'lihua_wallet_order/multi',
                    table: 'lihua_wallet_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'getmoney', title: __('Getmoney'), operate:'BETWEEN'},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'sn', title: __('Sn')},
                        {field: 'city_id', title: __('City_id'), operate: false,formatter:Controller.api.formatter.city_name},
                        {field: 'platform', title: __('Platform')},
                        {field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'pay_type', title: __('Pay_type'), searchList: {"1":__('Pay_type 1'),"2":__('Pay_type 2'),'6':'银联微信'}, formatter: Table.api.formatter.normal},
                        {field: 'mobile', title: __('Mobile')},
                        {field: 'actid', title: __('Actid')},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 1 北京 2 上海 3 常州 4 南京 5 苏州 6	无锡 7 广州
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                city_name: function (value, row, index) {
                    var city_arr = ["","北京","上海","常州","南京","苏州","无锡","广州"];
                    return city_arr[row.city_id];
                },
            }
        }
    };
    return Controller;
});